package com.mall.user.services;

import com.mall.user.ITokenToUserIdService;
import com.mall.user.dal.entitys.Member;
import com.mall.user.dal.entitys.User;
import com.mall.user.dal.entitys.UserVerify;
import com.mall.user.dal.persistence.MemberMapper;
import com.mall.user.dal.persistence.UserVerifyMapper;
import com.mall.user.utils.JwtTokenUtils;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @ClassName ITokenToUserIdServiceImpl
 * @Description
 * @Author 王昀昊
 * @Date 2021/8/24 21:46
 * @Version 1.0
 **/
@Service
@Component
public class ITokenToUserIdServiceImpl implements ITokenToUserIdService {

    @Autowired
    MemberMapper memberMapper;

    @Override
    public Long getUserId(String token) {
        String username = JwtTokenUtils.builder().token(token).build().freeJwt();
        Example example = new Example(Member.class);
        example.createCriteria().andEqualTo(username);
        Member member = memberMapper.selectOneByExample(example);
        return member.getId();
    }
}
